<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<title>class CategoriesController - Rails Application Documentation</title>

<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="./index.html">Home</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>app/controllers/categories_controller.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="ApplicationController.html">ApplicationController</a>
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-create">#create</a>
    
    <li><a href="#method-i-destroy">#destroy</a>
    
    <li><a href="#method-i-edit">#edit</a>
    
    <li><a href="#method-i-index">#index</a>
    
    <li><a href="#method-i-load">#load</a>
    
    <li><a href="#method-i-new">#new</a>
    
    <li><a href="#method-i-sort">#sort</a>
    
    <li><a href="#method-i-update">#update</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="./doc/README_FOR_APP.html">README_FOR_APP</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="./Account.html">Account</a>
  
    <li><a href="./AccountsController.html">AccountsController</a>
  
    <li><a href="./AccountsHelper.html">AccountsHelper</a>
  
    <li><a href="./ApplicationController.html">ApplicationController</a>
  
    <li><a href="./ApplicationHelper.html">ApplicationHelper</a>
  
    <li><a href="./CategoriesController.html">CategoriesController</a>
  
    <li><a href="./CategoriesHelper.html">CategoriesHelper</a>
  
    <li><a href="./Category.html">Category</a>
  
    <li><a href="./Eating.html">Eating</a>
  
    <li><a href="./EatingType.html">EatingType</a>
  
    <li><a href="./EatingsController.html">EatingsController</a>
  
    <li><a href="./EatingsHelper.html">EatingsHelper</a>
  
    <li><a href="./StatisticsController.html">StatisticsController</a>
  
    <li><a href="./StatisticsHelper.html">StatisticsHelper</a>
  
    <li><a href="./Transaction.html">Transaction</a>
  
    <li><a href="./TransactionsController.html">TransactionsController</a>
  
    <li><a href="./TransactionsHelper.html">TransactionsHelper</a>
  
    <li><a href="./User.html">User</a>
  
    <li><a href="./UsersController.html">UsersController</a>
  
    <li><a href="./UsersHelper.html">UsersHelper</a>
  
    <li><a href="./Weight.html">Weight</a>
  
    <li><a href="./WeightsController.html">WeightsController</a>
  
    <li><a href="./WeightsHelper.html">WeightsHelper</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class CategoriesController</h1>

  <div id="description" class="description">
    
  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-create" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">create</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="create-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create</span>
  <span class="ruby-ivar">@category</span> = <span class="ruby-constant">Category</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:category</span>])
  <span class="ruby-keyword">if</span>(<span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span>)
    <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">user</span> = <span class="ruby-identifier">current_user</span>
    <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">save</span>
        <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> {<span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">categories_path</span>}
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;new&quot;</span> }
        <span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">json</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">errors</span>, <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-value">:unprocessable_entity</span> }
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- create-source -->
          
        </div>

        

        
      </div><!-- create-method -->

    
      <div id="method-i-destroy" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">destroy</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="destroy-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 67</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">destroy</span>
  <span class="ruby-ivar">@category</span> = <span class="ruby-constant">Category</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
  <span class="ruby-keyword">if</span>(<span class="ruby-ivar">@category</span>.<span class="ruby-identifier">user_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>)
    <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">update_attribute</span>(<span class="ruby-value">:enabled</span>, <span class="ruby-keyword">false</span>)
    <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">save</span>
    <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">categories_url</span> }
      <span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">head</span> <span class="ruby-value">:no_content</span> }
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">return</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- destroy-source -->
          
        </div>

        

        
      </div><!-- destroy-method -->

    
      <div id="method-i-edit" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">edit</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="edit-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">edit</span>
  <span class="ruby-ivar">@category</span> = <span class="ruby-constant">Category</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
  <span class="ruby-keyword">if</span>(<span class="ruby-ivar">@category</span>.<span class="ruby-identifier">user_id</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>)
    <span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">return</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- edit-source -->
          
        </div>

        

        
      </div><!-- edit-method -->

    
      <div id="method-i-index" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">index</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="index-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 4</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">index</span>

<span class="ruby-keyword">end</span></pre>
          </div><!-- index-source -->
          
        </div>

        

        
      </div><!-- index-method -->

    
      <div id="method-i-load" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">load</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="load-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 8</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">load</span>
  <span class="ruby-identifier">field</span> = <span class="ruby-identifier">params</span>[<span class="ruby-value">:field</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">?</span> <span class="ruby-string">&quot;name&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:field</span>]
  <span class="ruby-identifier">direction</span> = <span class="ruby-identifier">params</span>[<span class="ruby-value">:direction</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">?</span> <span class="ruby-string">&quot;asc&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:direction</span>]
  <span class="ruby-identifier">sortStr</span> = <span class="ruby-identifier">field</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot; &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">direction</span>

  <span class="ruby-ivar">@categories</span> = <span class="ruby-constant">Category</span>.<span class="ruby-identifier">order</span>(<span class="ruby-identifier">sortStr</span>).<span class="ruby-identifier">find_all_by_user_id_and_enabled</span>(<span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>, <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">render</span> <span class="ruby-value">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;categories&quot;</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- load-source -->
          
        </div>

        

        
      </div><!-- load-method -->

    
      <div id="method-i-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 23</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">new</span>
  <span class="ruby-ivar">@category</span> = <span class="ruby-constant">Category</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">amount</span> = <span class="ruby-value">0</span>;
  <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">enabled</span> = <span class="ruby-keyword">true</span>;
<span class="ruby-keyword">end</span></pre>
          </div><!-- new-source -->
          
        </div>

        

        
      </div><!-- new-method -->

    
      <div id="method-i-sort" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">sort</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="sort-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">sort</span>
  <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">load_categories_path</span>(<span class="ruby-value">:field</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:field</span>], <span class="ruby-value">:direction</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:direction</span>])}
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- sort-source -->
          
        </div>

        

        
      </div><!-- sort-method -->

    
      <div id="method-i-update" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">update</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="update-source">
            <pre><span class="ruby-comment"># File app/controllers/categories_controller.rb, line 51</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">update</span>
  <span class="ruby-ivar">@category</span> = <span class="ruby-constant">Category</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
  <span class="ruby-keyword">if</span>(<span class="ruby-ivar">@category</span>.<span class="ruby-identifier">user_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>)
    <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:category</span>])
        <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> {<span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">categories_path</span>}
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;edit&quot;</span> }
        <span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">json</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@category</span>.<span class="ruby-identifier">errors</span>, <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-value">:unprocessable_entity</span> }
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">return</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- update-source -->
          
        </div>

        

        
      </div><!-- update-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

